package util

import (
	"crypto/md5"
	"fmt"
	"github.com/google/uuid"
	"hash/fnv"
	"strings"
)

func RandomUUID() string {
	u1 := uuid.New()
	return u1.String()
}

func SimpleUUID() string {
	u1 := uuid.New()
	return strings.ReplaceAll(u1.String(), "-", "")
}

// Md5ToString 生成md5
func Md5ToString(str string) string {
	return fmt.Sprintf("%x", md5.Sum([]byte(str)))
}

// Md5 生成md5
func Md5(b []byte) []byte {
	//return fmt.Sprintf("%x", md5.Sum(b))
	sum := md5.Sum(b)
	return sum[:]
}

func Hash32(b []byte) uint32 {
	h := fnv.New32a()
	h.Write(b)
	return h.Sum32()
}
